import com.beans.API;
import com.beans.User;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

import java.nio.file.attribute.AclFileAttributeView;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lenovo
 * Date: 2023-01-06
 * Time: 11:13
 */
public class App {
    public static void main1(String[] args) {
        //1.获取spring的上下文
        ApplicationContext context =
                new ClassPathXmlApplicationContext("spring-config.xml");
//        //2.根据beanid获取到bean对象
//        User user = (User) context.getBean("user");
//        //3.使用bean对象
//        user.sayHai("张三");
    }

    public static void main2(String[] args) {
        //1.得到beanfactory
        BeanFactory factory = new XmlBeanFactory(new ClassPathResource("spring-config.xml"));
        //2.得到bean对象
        User user = (User) factory.getBean("user");
        //3.使用bean对象
        user.sayHai("李四");

    }

    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
        API api  = (API) context.getBean("API");
        api.sayHi();
    }
}
